package com.fatdetection.demo.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fatdetection.demo.bean.ProjGroup;
import com.fatdetection.demo.mapper.GroupMapper;
import com.fatdetection.demo.service.GroupSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class GroupServiceImp implements GroupSevice {

    @Autowired
    GroupMapper groupMapper;

    @Override
    public List<ProjGroup> getGroupsByProjId(Integer projectId) {
        return groupMapper.selectList(new QueryWrapper<ProjGroup>()
        .eq("project_id", projectId));
    }

    @Override
    public Boolean insertGroup(ProjGroup group) {
        return groupMapper.insert(group) == 1;
    }

    @Override
    public Boolean delGroup(Integer groupId) {
        return groupMapper.delete(new QueryWrapper<ProjGroup>().eq("group_id", groupId)) == 1;
    }

    @Override
    public Boolean updateGroup(ProjGroup group) {
        return groupMapper.update(group
                , new UpdateWrapper<ProjGroup>()
                        .eq("group_id", group.getGroupId())) == 1;
    }

    @Override
    public List<ProjGroup> findAll() {
        return groupMapper.selectList(null);
    }

    @Override
    public List<ProjGroup> findByProj(String projectName) {
        return groupMapper.selectList(new QueryWrapper<ProjGroup>().eq("project_name", projectName));
    }

    @Override
    public List<ProjGroup> findByOpt(String optName) {
        return groupMapper.selectList(new QueryWrapper<ProjGroup>().eq("operator_name", optName));
    }

    @Override
    public List<ProjGroup> findBySchool(String schoolName) {
        return groupMapper.selectList(new QueryWrapper<ProjGroup>().eq("school_name", schoolName));
    }

    @Override
    public ProjGroup findByGroupName(String groupName) {
        return groupMapper.selectOne(new QueryWrapper<ProjGroup>().eq("group_name", groupName));
    }

    @Override
    public ProjGroup findById(Integer id) {
        return groupMapper.selectOne(new QueryWrapper<ProjGroup>().eq("group_id", id));
    }


}
